package com.example.superoa.model.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.dao.CalendarYfDao;
import com.example.superoa.model.mappers.CalendaryfMapper;
import com.example.superoa.model.pojos.CalendarYf;

@Service
@Transactional(rollbackFor=Exception.class)
public class CalendarYfService {
@Autowired
private CalendarYfDao cyd;
@Autowired
private CalendaryfMapper cm;

public CalendarYf findOne(String itime) {
	System.err.println(cyd.findOne(itime).getItime()+"==="+cyd.findOne(itime).getIremind());
	return cyd.findOne(itime);
}

public List<CalendarYf> findAll(String imouthyear) {
	return cyd.findAll(imouthyear);
}

public List<CalendarYf> findMany(String itime) {
	System.err.println("长度："+cyd.findMany(itime).size());
	return cyd.findMany(itime);
}

public JSONArray selectCalendarByid(String itime,int staff_id) {
	return cm.selectCalendarByid(itime, staff_id);
}

public JSONArray selectCalendarByidtwo(String imouthyear,int staff_id) {
	return cm.selectCalendarByidtwo(imouthyear, staff_id);
}

//新增提醒
public void addCalender(String a,String b,String c,int staff_id) {
	String itime=null;
	int i=b.indexOf("-");
	int j=b.lastIndexOf("-");
	
	String year=b.substring(0, i);
	String mouth=b.substring(i+1, j);
	String day=b.substring(j+1);
	
	String imouthyear=null;
	String[] array1= {"01","02","03","04","05","06","07","08","09","10","11","12"};
	String[] array2= {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
	for(int z=0;z<12;z++) {
		if(mouth.equals(array1[z])) {
			imouthyear=array2[z]+" "+year;
		}
	}
	
	String imouth=mouth.substring(0, 1);
	String iday=day.substring(0, 1);
	if(imouth.equals("0")) {
		mouth=mouth.substring(1);
	}
	if(iday.equals("0")) {
		day=day.substring(1);
	}
	
	itime=year+","+mouth+","+day;
	
	CalendarYf cy=new CalendarYf();
	cy.setIremind(a);
	cy.setImouthyear(imouthyear);
	cy.setItime(itime);
	cy.setIdegree(c);
	cy.setStaff_id(staff_id);
	cyd.save(cy);
}

}
